﻿@model XPressify.Models.SelectParticipantsModel

@{
    ViewBag.Title = "Select participants";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<script type="text/javascript">


    function checkAll() {
        var element = document.getElementsByName('DeleteBox');
        var i = 0;
        while (true) {
            var element = document.getElementsByName('AllFriends[' + i + '].Selected');
            if (element[0] == null) {
                break;
            }
            element[0].checked = true;
            i++;
        }
        var btn = document.getElementById("checkBtn")
        btn.onclick = uncheckAll;
        btn.value = "Uncheck all"
    }
    function uncheckAll() {
        var element = document.getElementsByName('DeleteBox');
        var i = 0;
        while (true) {
            var element = document.getElementsByName('AllFriends[' + i + '].Selected');
            if (element[0] == null) {
                break;
            }
            element[0].checked = false;
            i++;
        }
        var btn = document.getElementById("checkBtn")
        btn.onclick = checkAll;
        btn.value = "Check all"
    }
</script>



<h2 style="color:#222">Select participants</h2>

@using (Html.BeginForm())
{
    <div align="right"><input type="button" class="abtn" id="checkBtn" name="UnCheckAll" value="Check All" onclick="checkAll()" /></div>
<table>
    <tr>
        <th width="50px">
            Participant
        </th>
        <th></th>
        <th>
            Select
        </th>
        <th>
                            
        </th>
    </tr>
    @{
    var index = 0;
    foreach (var participant in Model.AllFriends)
    {
            <tr>
                <td>
                    <a href='@Url.Action("ProfileView", "Profile", new { id = participant.Id })' class="nobtn">
                        <img src= "@participant.ProfilePicturePath" alt="Profile picture" title="Profile picture" style="width: 50px;height: 50px;" />
                    </a>
                                    
                </td>
                <td>
                    @Html.ActionLink(participant.FullName, "ProfileView", "Profile", new { id = participant.Id }, new { @class = "nobtn" })
                </td>
                <td>
                    @Html.CheckBoxFor(model => model.AllFriends[index].Selected)
                </td>
                <td>
                    @Html.HiddenFor(model => model.AllFriends[index].Id)
                </td>
            </tr>
               index++;
    }
    }
</table>

    <p>
        <input type="submit" value="Select" />
    </p>
}